home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Interfaces / PInterfaces / Math64.p < prev    next >
Encoding:
Text File  |  1996-09-22  |  7.7 KB  |  225 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Math64.p
  3.  
  4.      Contains:    64-bit integer math Interfaces.
  5.  
  6.      Version:    Technology:    Math64Lib
  7.                  Package:    Universal Interfaces 2.1.4
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. }
  19. {$IFC UNDEFINED UsingIncludes}
  20. {$SETC UsingIncludes := 0}
  21. {$ENDC}
  22.  
  23. {$IFC NOT UsingIncludes}
  24.  UNIT Math64;
  25.  INTERFACE
  26. {$ENDC}
  27.  
  28. {$IFC UNDEFINED __MATH64__}
  29. {$SETC __MATH64__ := 1}
  30.  
  31. {$I+}
  32. {$SETC Math64Includes := UsingIncludes}
  33. {$SETC UsingIncludes := 1}
  34.  
  35. {$IFC UNDEFINED __TYPES__}
  36. {$I Types.p}
  37. {$ENDC}
  38.  
  39. {$PUSH}
  40. {$ALIGN MAC68K}
  41. {$LibExport+}
  42.  
  43. {
  44. --------------------------------------------------------------------------------
  45.                 These routines are intended to provide C software support for
  46.                 64 bit integer types.  Their behavior should mimic anticipated
  47.                 64 bit hardware. This implementation should replace use of the
  48.                 "wide" type found in PowerPC.
  49.  
  50.     The following routines are available for performing math on 64-bit integers:
  51.     
  52.     S64Max
  53.                 Returns the largest representable SInt64.
  54.     S64Min
  55.                 Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  56.                 (absolute value) of this number is not representable in an SInt64.
  57.                 That means that S64Negate(S64Min) is not representable (in fact,
  58.                 it returns S64Min).
  59.     S64Add
  60.                 Adds two integers, producing an integer result.  If an overflow
  61.                 occurs the result is congruent mod (2^64) as if the operands and
  62.                 result were unsigned.  No overflow is signaled.
  63.     
  64.     S64Subtract
  65.                 Subtracts two integers, producing an integer result.  If an overflow
  66.                 occurs the result is congruent mod (2^64) as if the operands and
  67.                 result were unsigned.  No overflow is signaled.
  68.  
  69.     S64Negate
  70.                 Returns the additive inverse of a signed number (i.e. it returns
  71.                 0 - the number).  S64Negate (S64Min) is not representable (in fact,
  72.                 it returns S64Min).
  73.     
  74.     S64Absolute
  75.                 Returns the absolute value of the number (i.e. the number if
  76.                 it is positive, or 0 - the number if it is negative).
  77.                 See S64Negate above.
  78.                 
  79.     S64Multiply
  80.                 Multiplies two signed numbers, producing a signed result.  Overflow
  81.                 is ignored and the low-order part of the product is returned.  The
  82.                 sign of the result is not guaranteed to be correct if the magnitude
  83.                 of the product is not representable.
  84.     S64Divide
  85.                 Divides dividend by divisor, returning the quotient.  The remainder
  86.                 is returned in *remainder if remainder (the pointer) is non-NULL.
  87.                 The sign of the remainder is the same as the sign of the dividend
  88.                 (i.e. it takes the absolute values of the operands, does the division,
  89.                 then fixes the sign of the quotient and remainder).  If the divisor
  90.                 is zero, then S64Max() will be returned (or S64Min() if the dividend
  91.                 is negative), and the remainder will be the dividend; no error is
  92.                 reported.
  93.     
  94.     S64Set
  95.                 Given an SInt32, returns an SInt64 with the same value.  Use this
  96.                 routine instead of coding 64-bit constants (at least when the
  97.                 constant will fit in an SInt32).
  98.     
  99.     S64SetU
  100.                 Given a UInt32, returns a SInt64 with the same value.
  101.     
  102.     S64Compare
  103.                 Given two signed numbers, left and right, returns an
  104.                 SInt32 that compares with zero the same way left compares with
  105.                 right.  If you wanted to perform a comparison on 64-bit integers
  106.                 of the form:
  107.                         operand_1 <operation> operand_2
  108.                 then you could use an expression of the form:
  109.                         xxxS64Compare(operand_1,operand_2) <operation> 0
  110.                 to test for the same condition.
  111.                 
  112.                 CAUTION: DO NOT depend on the exact value returned by this routine.
  113.                 Only the sign (i.e. positive, zero, or negative) of the result is
  114.                 guaranteed.
  115.  
  116.     S64And, S64Or, S64Eor and S64Not
  117.     
  118.                 Return Boolean (1 or 0) depending on the outcome of the logical
  119.                 operation.
  120.  
  121.     S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  122.     
  123.                 Return the Bitwise result.
  124.                 
  125.     S64ShiftRight and S64ShiftLeft
  126.     
  127.                 The lower 7 bits of the shift argument determines the amount of 
  128.                 shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  129.                 is a logical shift.
  130.  
  131.     SInt64ToLongDouble
  132.                 
  133.                 Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  134.                 long doubles, thus, the binary -> decimal conversion routines
  135.                 in fp.h can be used to achieve SInt64 -> long double -> decimal
  136.                 conversions.
  137.                 
  138.     LongDoubleToSInt64
  139.     
  140.                 Converts a long double to a SInt64.  Any decimal string that fits
  141.                 into a SInt64 can be converted exactly into a long double, using the
  142.                 conversion routines found in fp.h.  Then this routine can be used
  143.                 to complete the conversion to SInt64.
  144.                 
  145.                 
  146.     
  147.     The corresponding UInt64 routines are also included.
  148.     
  149. --------------------------------------------------------------------------------
  150. }
  151. TYPE
  152.     SInt64Ptr = ^SInt64;
  153.     SInt64 = RECORD
  154.         hi:                        SInt32;
  155.         lo:                        UInt32;
  156.     END;
  157.  
  158.     UInt64Ptr = ^UInt64;
  159.     UInt64 = RECORD
  160.         hi:                        UInt32;
  161.         lo:                        UInt32;
  162.     END;
  163.  
  164. {$IFC GENERATINGPOWERPC }
  165. FUNCTION S64Max: SInt64; C;
  166. FUNCTION S64Min: SInt64; C;
  167. FUNCTION S64Add(x: SInt64; y: SInt64): SInt64; C;
  168. FUNCTION S64Subtract(left: SInt64; right: SInt64): SInt64; C;
  169. FUNCTION S64Negate(value: SInt64): SInt64; C;
  170. FUNCTION S64Absolute(value: SInt64): SInt64; C;
  171. FUNCTION S64Multiply(xparam: SInt64; yparam: SInt64): SInt64; C;
  172. FUNCTION S64Divide(dividend: SInt64; divisor: SInt64; VAR remainder: SInt64): SInt64; C;
  173. FUNCTION S64Set(value: SInt32): SInt64; C;
  174. FUNCTION S64SetU(value: UInt32): SInt64; C;
  175. FUNCTION S32Set(value: SInt64): SInt32; C;
  176. FUNCTION S64Compare(left: SInt64; right: SInt64): LONGINT; C;
  177. FUNCTION S64And(left: SInt64; right: SInt64): BOOLEAN; C;
  178. FUNCTION S64Or(left: SInt64; right: SInt64): BOOLEAN; C;
  179. FUNCTION S64Eor(left: SInt64; right: SInt64): BOOLEAN; C;
  180. FUNCTION S64Not(value: SInt64): BOOLEAN; C;
  181. FUNCTION S64BitwiseAnd(left: SInt64; right: SInt64): SInt64; C;
  182. FUNCTION S64BitwiseOr(left: SInt64; right: SInt64): SInt64; C;
  183. FUNCTION S64BitwiseEor(left: SInt64; right: SInt64): SInt64; C;
  184. FUNCTION S64BitwiseNot(value: SInt64): SInt64; C;
  185. FUNCTION S64ShiftRight(value: SInt64; shift: UInt32): SInt64; C;
  186. FUNCTION S64ShiftLeft(value: SInt64; shift: UInt32): SInt64; C;
  187. FUNCTION SInt64ToLongDouble(value: SInt64): LongDouble; C;
  188. FUNCTION LongDoubleToSInt64(value: LongDouble): SInt64; C;
  189. FUNCTION U64Max: UInt64; C;
  190. FUNCTION U64Add(x: UInt64; y: UInt64): UInt64; C;
  191. FUNCTION U64Subtract(left: UInt64; right: UInt64): UInt64; C;
  192. FUNCTION U64Multiply(xparam: UInt64; yparam: UInt64): UInt64; C;
  193. FUNCTION U64Divide(dividend: UInt64; divisor: UInt64; VAR remainder: UInt64): UInt64; C;
  194. FUNCTION U64Set(value: SInt32): UInt64; C;
  195. FUNCTION U64SetU(value: UInt32): UInt64; C;
  196. FUNCTION U32SetU(value: UInt64): UInt32; C;
  197. FUNCTION U64Compare(left: UInt64; right: UInt64): LONGINT; C;
  198. FUNCTION U64And(left: UInt64; right: UInt64): BOOLEAN; C;
  199. FUNCTION U64Or(left: UInt64; right: UInt64): BOOLEAN; C;
  200. FUNCTION U64Eor(left: UInt64; right: UInt64): BOOLEAN; C;
  201. FUNCTION U64Not(value: UInt64): BOOLEAN; C;
  202. FUNCTION U64BitwiseAnd(left: UInt64; right: UInt64): UInt64; C;
  203. FUNCTION U64BitwiseOr(left: UInt64; right: UInt64): UInt64; C;
  204. FUNCTION U64BitwiseEor(left: UInt64; right: UInt64): UInt64; C;
  205. FUNCTION U64BitwiseNot(value: UInt64): UInt64; C;
  206. FUNCTION U64ShiftRight(value: UInt64; shift: UInt32): UInt64; C;
  207. FUNCTION U64ShiftLeft(value: UInt64; shift: UInt32): UInt64; C;
  208. FUNCTION UInt64ToLongDouble(value: UInt64): LongDouble; C;
  209. FUNCTION LongDoubleToUInt64(value: LongDouble): UInt64; C;
  210. FUNCTION UInt64ToSInt64(value: UInt64): SInt64; C;
  211. FUNCTION SInt64ToUInt64(value: SInt64): UInt64; C;
  212. {$ENDC}
  213.  
  214.  
  215. {$ALIGN RESET}
  216. {$POP}
  217.  
  218. {$SETC UsingIncludes := Math64Includes}
  219.  
  220. {$ENDC} {__MATH64__}
  221.  
  222. {$IFC NOT UsingIncludes}
  223.  END.
  224. {$ENDC}
  225.